package com.autologistics.service;

import java.util.List;

import com.autologistics.dao.UserDao;
import com.autologistics.model.Disparter;
import com.autologistics.model.User;
import com.autologistics.util.PageBean;

public class UserServiceImpl implements UserService{
	UserDao userDao;

	public UserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}
	public List<User> listAll(){
		return userDao.listAll();
	}
	public User getById(int id){
		return userDao.getById(id);
	}
	public User getByAccountPwd(String ac,String pwd){
		return userDao.getByAccountPwd(ac, pwd);
	}
	public void save(User user){
		userDao.save(user);
	}
	public void update(User user){
		userDao.update(user);
	}
	public User getByAccount(String ac){
		return userDao.getByAccount(ac);
	}
	public PageBean queryForOnePage(final int pageSize, int page,int allRow){
		System.out.println("allRow    "+allRow);
		int totalPage = PageBean.countTotalPage(pageSize, allRow); //总页数  
		System.out.println("totalPage    "+totalPage);
		
		final int offset = PageBean.countOffset(pageSize, page); //当前页开始记录  
		System.out.println("offset    "+offset);
		final int length = pageSize; // 每页记录数    
		final int currentPage = PageBean.countCurrentPage(page); // 当前页    
		List<User> list=userDao.queryForOnePage(offset, length);
		//把分页信息保存到Bean当中    
		PageBean pageBean  = new PageBean();    
		pageBean.setPageSize(pageSize);    
		pageBean.setCurrentPage(currentPage);    
		pageBean.setAllRow(allRow);    
		pageBean.setTotalPage(totalPage);    
		pageBean.setUserList(list);    
		return pageBean; 
		
		
	}
}
